package com.sias;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2023/6/14 22:50
 */
public class A13 {
  public static void main(String[] args) throws Exception {
    Foo proxy = new $Proxy0(new InvocationHandler() {
      @Override
      public Object invoke(Object proxy,Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
        System.out.println("before");
        // new A13.Target().foo();
        Object result = method.invoke(new Target(), args);
        return result;
      }
    });
    proxy.foo();
    proxy.bar();
  }

  interface Foo {
    void foo() throws Exception;

    int bar() throws Exception;
  }

  interface InvocationHandler {
    Object invoke(Object object,Method method, Object[] args) throws InvocationTargetException, IllegalAccessException;
  }

  static class Target implements Foo {
    @Override
    public void foo() {
      System.out.println("foo()");
    }

    @Override
    public int bar() {
      System.out.println("bar()");
      return 100;
    }
  }
}
